<?php
/*
 * Created on 22.12.2005
 *
 */

class c_urlHandler
{

    var $var;

    function startElement (& $sender, $attrs)
    {
        if (!$attrs['value'] && !$attrs['action'])
        {
            die ("Attribute value or action is missing in url tag!\n");
        }
        $attrs['tag'] = 'url';
        if ($attrs['var'])
        {
            $var = substr($attrs['var'], 1, strlen($attrs['var'])-2);
            if (!preg_match('/\w+/', $var))
                die ("Attribute var must not contain EL code\n");
            $attrs['var'] = $var;
            $this->var = $var;
        }
        else
            unset($this->var); 
        $sender->pushParent($attrs);
        if ($attrs['value'])
        {
            $sender->appendCode('$'."__url = new URL(".$attrs['value'].");\n");
        }
        else
        {
            $sender->appendCode('$'."__url = new URL();\n");
        }
        if ($attrs['action'])
        {
            $sender->appendCode('$'."__url->setAction(".$attrs['action'].");\n");
        }
    }

    function endElement (& $sender)
    {
        $parent = $sender->topParent();
        if ($this->var)
            $sender->appendCode('$'.$this->var.' = $'."__url->toString();\n");
        else
            $sender->appendCode('print $'."__url->toString();\n");
        $sender->popParent();
    }

}

?>